package com.dh.leetcode.two;

import com.dh.leetcode.common.TreeNode;
import com.dh.leetcode.common.TreeNodeIterator;
import org.junit.Test;

/**
 * @ClassName: _222_Count_complete_tree_nodes
 * @Description: 222. 完全二叉树的节点个数
 * https://leetcode-cn.com/problems/count-complete-tree-nodes/
 * @Author: shouzimu
 * @Date: 2020/11/24 9:37
 */
public class _222_Count_complete_tree_nodes {
    static int num = 0;

    public int countNodes(TreeNode root) {
        num = 0;
        postOrder(root);
        return num;
    }

    void postOrder(TreeNode node) {
        if (node == null) {
            return;
        }
        postOrder(node.left);
        postOrder(node.right);
        num++;
    }

    @Test
    public void countNodesTest() {
        Integer[] data = new Integer[]{1, 2, 3, 4, 5, 6};
        TreeNode tree = TreeNodeIterator.initTestTree(data);
        System.out.println(countNodes(tree));
    }
}
